<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 68KB
 *
 * An open source knowledge base script
 *
 * @package		68kb
 * @author		68kb Dev Team
 * @copyright	Copyright (c) 2009, 68 Designs, LLC
 * @license		http://68kb.com/user_guide/license.html
 * @link		http://68kb.com
 * @since		Version 1.0
 */

// ------------------------------------------------------------------------

/**
 * 68KB Core Loader
 *
 * This extends the CI_Loader library so we can set the views to another directory.
 *
 * @package		68kb
 * @subpackage	Libraries
 * @category	Libraries
 * @author		68kb Dev Team
 * @link		http://68kb.com/
 * @version 	$Id: core_Loader.php 158 2009-12-11 03:25:57Z suzkaw68 $
 */
class core_Loader extends CI_Loader{
	
	var $_ci_view_path		= '';
	
	function __construct()
	{
		parent::__construct();
		$this->_ci_view_path = KBPATH .'themes/';
		$this->core_plugins();
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Load Module View
	 *
	 * This function loads the module template files.
	 * <?php $this->load->module_view('module_name', 'template_file'); ?>
	 *
	 * @access	public
	 * @param	string
	 * @param	string
	 * @param	array
	 * @return	void
	 */
	function module_view($path, $view, $vars = array(), $return = FALSE)
	{
		$full_path = EXTPATH .'modules/'.$path.'/templates/'.$view.'.php';
		if (file_exists($full_path)) 
		{
			return $this->_ci_load(array('_ci_path' => $full_path, '_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
		}
		else
		{
			show_error('Unable to load the requested module template file: '.$view);
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Load Template View
	 *
	 * This function loads the template admin files.
	 * <?php $this->load->template_view('module_name', 'template_file'); ?>
	 *
	 * @access	public
	 * @param	string
	 * @param	string
	 * @param	array
	 * @return	void
	 */
	function template_view($path, $view, $vars = array(), $return = FALSE)
	{
		$full_path = FCPATH .'themes/'.$path.'/'.$view.'.php';
		if (file_exists($full_path)) 
		{
			return $this->_ci_load(array('_ci_path' => $full_path, '_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
		}
		else
		{
			show_error('Unable to load the requested template file: '.$view);
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Load Plugin
	 *
	 * This function loads the specified plugin.
	 *
	 * @access	public
	 * @param	array
	 * @return	void
	 */
	function core_plugins()
	{
		// first app plugins
		$opendir = opendir(APPPATH .'plugins');
 		while (false !== ($plugin = readdir($opendir)))
		{
			if ($plugin != '.' && $plugin != '..')
			{
				$plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi');	
				if (isset($this->_ci_plugins[$plugin]))
				{
					continue;
				}
				if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
				{
					include_once(APPPATH.'plugins/'.$plugin.EXT);	
				}
			}
		}
		
		$opendir = opendir(EXTPATH .'plugins');
 		while (false !== ($plugin = readdir($opendir)))
		{
			// Ignores . and .. that opendir displays
			if ($plugin != '.' && $plugin != '..')
			{
				$plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi');	
				if (isset($this->_ci_plugins[$plugin]))
				{
					continue;
				}
				
				if (file_exists(EXTPATH.'plugins/'.$plugin.EXT))
				{
					include_once(EXTPATH.'plugins/'.$plugin.EXT);
				}
				else
				{
					if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
					{
						include_once(BASEPATH.'plugins/'.$plugin.EXT);	
					}
					else
					{
						continue;
					}
				}
				log_message('debug', 'Plugin loaded: '.$plugin);
			}
		}
		closedir($opendir);
	}
}

/* End of file core_loader.php */
/* Location: ./upload/includes/application/libraries/core_loader.php */ 